package charles.testproject.guidemos;

import java.awt.Button;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;

public class GridBagLayoutDemo1 extends JFrame {
	private Button buttons[] = new Button[7];
	private GridBagLayout gridbay = new GridBagLayout();
	private GridBagConstraints c = new GridBagConstraints();
	
	public GridBagLayoutDemo1(String title) {
		super.setTitle(title);
		this.setLayout(gridbay);
		
		for(int i = 0; i < buttons.length; i++) {
			buttons[i] = new Button("Button" + i);
		}
		
		c.fill = GridBagConstraints.BOTH;
		this.addComponents(buttons[0], 0, 0, 1, 3);
		
		c.fill = GridBagConstraints.HORIZONTAL;
		this.addComponents(buttons[1], 0, 1, 2, 1);
		this.addComponents(buttons[2], 2, 1, 2, 1);
		
		c.weightx = 1000;
		c.weighty = 1;
		c.fill = GridBagConstraints.BOTH;
		this.addComponents(buttons[3], 1, 1, 1, 1);
		c.weightx = 0;
		c.weighty = 0;
		this.addComponents(buttons[4], 1, 2, 1, 1);
		
		
		this.addComponents(buttons[5], 3, 0, 2, 1);
		this.addComponents(buttons[6], 3, 2, 1, 1);
		
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(300,200);
		this.pack();
		this.setVisible(true);
	}
	
	private void addComponents(Component component , int row, int column,
			                   int width, int height) {
		c.gridx = column;
		c.gridy = row;
		c.gridwidth = width;
		c.gridheight = height;
		gridbay.setConstraints(component,c);
		this.add(component);
		
	}
	
	public static void main(String[] args) {
		GridBagLayoutDemo1 GBL = new GridBagLayoutDemo1("GridBagLayoutDemo");
	}

}
